package com.pub.stripe.controller;

import com.pub.stripe.service.CallbackService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/stripe")
public class CallbackController {
    @Autowired
    private CallbackService callbackService;

    @GetMapping("/callback/success")
    public void success(String orderId)  {
        System.out.println("调用success成功：" + orderId);
    }

    @GetMapping("/callback/cancel")
    public void cancel(String orderId)  {
        System.out.println("调用cancel成功：" + orderId);
    }

    /**
     * webhook回调
     * @return 返回处理状态（验签不通过拒绝）
     */
    @PostMapping(value = "/callback/webhook")
    public Object webhook(HttpServletRequest request, HttpServletResponse response){
        return callbackService.webhook(request,response);
    }
}
